public class code {
    //判断链表是否成环：快慢指针，一个走一步，一个走两步，相遇就成环，反之则未成环
    public boolean hasCycle(ListNode head) {
        ListNode fast = head;
        ListNode slow = head;
        while(fast != null && fast.next != null) {
            fast = fast.next.next;
            slow = slow.next;
            if(fast == slow) {
                return true;
            }
        }
        return false;
}
